package com.enn.demo.core.domain.model.person;

import com.enn.demo.core.domain.shared.enums.StatusEnum;
import com.enn.demo.core.domain.shared.Entity;
import com.enn.demo.core.domain.model.user.UserName;

/**
 * 用户
 *
 * @author haoxin
 * @date 2021-02-02
 **/
public class Person implements Entity<Person> {

    /**
     * UserId
     */
    private PersonId personId;

    /**
     * 用户名
     */
    private UserName userName;

    /**
     * 年龄
     */
    private Age age;

    /**
     * 生日
     */
    private Birthday birthday;

    /**
     * 状态
     */
    private StatusEnum status;

    public Person(PersonId personId,UserName userName, Age age, Birthday birthday,StatusEnum status) {
        this.personId=personId;
        this.userName = userName;
        this.status = status;
        this.age = age;
        this.birthday = birthday;
    }

    public Person(UserName userName, Age age, Birthday birthday) {
        this.userName = userName;
        this.status = StatusEnum.ENABLE;
        this.age = age;
        this.birthday = birthday;
    }

    /**
     * 是否有效
     * @return
     */
    public boolean isEnable() {
        return status == StatusEnum.ENABLE;
    }

    @Override
    public boolean sameIdentityAs(Person other) {
        return other != null && personId.sameValueAs(other.personId);
    }

    /**
     * 禁用
     */
    public void disable() {
        StatusEnum status = this.status == StatusEnum.DISABLE? StatusEnum.ENABLE: StatusEnum.DISABLE;
        this.status = status;
    }

    public PersonId getPersonId() {
        return personId;
    }

    public UserName getUserName() {
        return userName;
    }

    public Age getAge() {
        return age;
    }

    public Birthday getBirthday() {
        return birthday;
    }

    public StatusEnum getStatus() {
        return status;
    }

}
